import axios from 'axios'

const instance = axios.create({
    baseURL: 'http://127.0.0.1:8888/api/private/v1',
    timeout: 5000
})

// 请求拦截【instance.interceptors.request.use(cb, cb)】
instance.interceptors.request.use(config => {
    // config.headers.token = "xxxx"
    let token = sessionStorage.getItem('token')
    if(token){
        config.headers['Authorization'] = token
    }
    return config;
}, err => {
    return Promise.reject(err)
})

// 响应拦截【instance.interceptors.response.use(cb, cb)】
instance.interceptors.response.use(result => {
    return result.data;
}, err => {
    return Promise.reject(err)
})

export default instance;